cmake_minimum_required(VERSION 3.10)

project(dna LANGUAGES CXX)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release)
endif()

message("It's in [${CMAKE_BUILD_TYPE}] mode")

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

find_package(OpenMP REQUIRED)
if(MSVC)
    add_compile_options(-openmp:llvm)
else()
    add_compile_options(-fopenmp)
    link_libraries(OpenMP::OpenMP_CXX)
endif()

add_subdirectory(pybind11)

include_directories(src/tools)

file(GLOB_RECURSE SRC CONFIGURE_DEPENDS src/*.cpp src/*.h src/*.hpp)

add_executable(${PROJECT_NAME}_bin ${SRC})

pybind11_add_module(${PROJECT_NAME} ${SRC})

target_compile_definitions(${PROJECT_NAME} PRIVATE DNA_IS_PYBIND)

# add_custom_command(
#     POST_BUILD
#     TARGET ${PROJECT_NAME}
#     COMMAND ${CMAKE_COMMAND} copy   
# )

file(GLOB ASSETS *.p*)
set(COPY_COMMANDS)

foreach(ASSET ${ASSETS})
    get_filename_component(FILENAME ${ASSET} NAME)
    list(
        APPEND COPY_COMMANDS
        COMMAND ${CMAKE_COMMAND} -E copy
        ${ASSET}            # 源文件路径
        "$<TARGET_FILE_DIR:${PROJECT_NAME}>/${FILENAME}"   
    )           # 目标文件路径
    Message("Copying ${ASSET} to the build directory")
endforeach()

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
    ${COPY_COMMANDS}
)